Do you use macOS as the target, or do you run your unmodified iOS App on MacOS?
Because on native macOS Applications, your code will work as expected.
Hope that helps!
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: